Skip to content

refactor: update all relative export paths to use ts extension #541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

michaelfaith
Copy link
Contributor

@michaelfaith michaelfaith commented Aug 5, 2025

Coming from #540. This change shifts all relative imports to use .ts extensions, and enables rewriteRelativeImportExtensions in the tsconfig. Unfotunately tsup has a bug when using this setting (egoist/tsup#1271), so I switched bundlers to tsdown the Vite community's new tsup alternative (which does support this).

I also updated the lint CI step to force using the latest LTS (22.18.0) which comes with native type stripping. I also added the eslint flag that allows eslint to use native type stripping.

@michaelfaith michaelfaith marked this pull request as ready for review August 5, 2025 02:22
@michaelfaith michaelfaith changed the title Refactor/change relative import extensions refactor: update all relative export paths to use ts extension Aug 5, 2025
@aladdin-add
Copy link
Contributor

tbh, I don't see the need to use tsup/tsdown. can we just use tsc:

  • "build": "tsc"
  • "test:typings": "tsc --no-emit"

@michaelfaith
Copy link
Contributor Author

Honestly, that's fair, since we're not bundling. The only thing is that those could be faster, but I'd have to do a comparison (if that's important to you).

@bmish
Copy link
Member

bmish commented Aug 8, 2025

Are .ts imports desirable for us regardless of these tooling choices? Any other pros and cons to switching to them?

@michaelfaith
Copy link
Contributor Author

Are .ts imports desirable for us regardless of these tooling choices? Any other pros and cons to switching to them?

The two main motivators i see are:

  1. Allows use of node's native type stripping
  2. More clear to newer devs, since the extension matches the imported source file's extension.

@michaelfaith michaelfaith force-pushed the refactor/change-relative-import-extensions branch from bd53ff1 to bdc07e0 Compare August 8, 2025 22:05
"lint:js": "eslint --cache --ignore-pattern \"**/*.md\"",
"lint:js-docs": "eslint --no-inline-config \"**/*.md\"",
"lint:js": "eslint --cache --ignore-pattern \"**/*.md\" --flag unstable_native_nodejs_ts_config",
"lint:js-docs": "eslint --no-inline-config \"**/*.md\" --flag unstable_native_nodejs_ts_config",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get rid of jiti if we're using this flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We wouldn't need it for the eslint run anymore. But it’s still being used by eslint-remote-tester to parse that config. And, unfortunately, they don't have an option to use node's built-in, like eslint does.

@bmish
Copy link
Member

bmish commented Aug 8, 2025

Just want to verify the output would still be compatible with the minimum Node versions we support? (20.19.0, 22.13.1 which don't support type-stripping yet). May be worth adding these versions to the CI workflow for running tests.

@michaelfaith
Copy link
Contributor Author

michaelfaith commented Aug 9, 2025

Just want to verify the output would still be compatible with the minimum Node versions we support? (20.19.0, 22.13.1 which don't support type-stripping yet). May be worth adding these versions to the CI workflow for running tests.

Yes, the output tsdown generates still has .js extensions on the imports, and this wouldn't change the compatability of what it emits. I can prepare a before / after diff to share?

Unfortunately, adding those versions to the test matrix wouldn't really be an adequate test, since the tests are run on source rather than the build output. But i like that idea.

Copy link
Member

@bmish bmish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

dts: true,
entry: ['lib/**/*.ts'],
format: ['esm'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any behavior changes from this tsup/tsdown conversion?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's meant to be a drop in replacement, just faster. If we were able to set isolatedModules to true in the tsconfig, it would be even faster. But the way the plugin is setup, we can't really do that, and still get rich type information. So, yeah, just swapping one for the other, won't change anything. I was able to remove some of those settings because tsdown will infer them from the package.json.

@bmish bmish merged commit 01c526e into eslint-community:main Aug 9, 2025
7 checks passed
@michaelfaith michaelfaith deleted the refactor/change-relative-import-extensions branch August 10, 2025 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants